package com.fc.test.service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.fc.test.mapper.auto.TAbbCommissionMapper;
import com.fc.test.mapper.auto.TAbbMemberMapper;
import com.fc.test.mapper.auto.TAbbOrderMapper;
import com.fc.test.model.auto.*;
import com.fc.test.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.fc.test.common.base.BaseService;
import com.fc.test.common.support.Convert;
import com.fc.test.mapper.auto.TAbbAixinMapper;
import com.fc.test.model.custom.Tablepar;
import com.fc.test.util.SnowflakeIdWorker;
import org.springframework.transaction.annotation.Transactional;

/**
 * Service
* @Title: TAbbAixinService.java 
* @Package com.fc.test.entity 
* @author fuce
* @email 87766867@qq.com
* @date 2019-08-19 14:45:27  
 */
@Service
public class TAbbAixinService implements BaseService<TAbbAixin, TAbbAixinExample> {
	@Autowired
	private TAbbAixinMapper tAbbAixinMapper;

	@Autowired
	private TAbbMemberMapper memberMapper;

	/**
	 * 分页查询
	 *
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	public PageInfo<TAbbAixin> list(Tablepar tablepar, String name,Integer status) {
		TAbbAixinExample testExample = new TAbbAixinExample();
		testExample.setOrderByClause("id ASC");
		if (name != null && !"".equals(name)) {
			testExample.createCriteria().andTitleLike("%" + name + "%");
		}
		if (status != null && status!=-1) {
			testExample.createCriteria().andStatusEqualTo(status);
		}
		PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());
		List<TAbbAixin> list = tAbbAixinMapper.selectByExample(testExample);
		PageInfo<TAbbAixin> pageInfo = new PageInfo<TAbbAixin>(list);
		return pageInfo;
	}

	@Override
	@Transactional
	public int deleteByPrimaryKey(String ids) {
		List<String> lista = Convert.toListStrArray(ids);
		TAbbAixinExample example = new TAbbAixinExample();
		example.createCriteria().andIdIn(lista);
		return tAbbAixinMapper.deleteByExample(example);
	}


	@Override
	public TAbbAixin selectByPrimaryKey(String id) {

		return tAbbAixinMapper.selectByPrimaryKey(id);
	}


	@Override
	public int updateByPrimaryKeySelective(TAbbAixin record) {
		return tAbbAixinMapper.updateByPrimaryKeySelective(record);
	}

	/**
	 * 添加
	 */
	@Override
	public int insertSelective(TAbbAixin record) {
		//添加雪花主键id
		record.setId(SnowflakeIdWorker.getUUID());
		return tAbbAixinMapper.insertSelective(record);
	}


	@Override
	public int updateByExampleSelective(TAbbAixin record, TAbbAixinExample example) {

		return tAbbAixinMapper.updateByExampleSelective(record, example);
	}


	@Override
	public int updateByExample(TAbbAixin record, TAbbAixinExample example) {

		return tAbbAixinMapper.updateByExample(record, example);
	}

	@Override
	public List<TAbbAixin> selectByExample(TAbbAixinExample example) {

		return tAbbAixinMapper.selectByExample(example);
	}


	@Override
	public long countByExample(TAbbAixinExample example) {

		return tAbbAixinMapper.countByExample(example);
	}


	@Override
	public int deleteByExample(TAbbAixinExample example) {

		return tAbbAixinMapper.deleteByExample(example);
	}

	public List<TAbbAixin> getAixinByPage(int page,int type){
		Map<String,Object> paramMap = new HashMap<>();
		paramMap.put("page",page);
		paramMap.put("type",type);
		List<TAbbAixin> list = tAbbAixinMapper.getAixinByPage(paramMap);
		return list;
	}

	public int releaseAixin(TAbbAixin tAbbAixin){

		TAbbMember member = memberMapper.selectByPrimaryKey(tAbbAixin.getUserid());

		tAbbAixin.setId(SnowflakeIdWorker.getUUID());
		tAbbAixin.setCreattime(DateUtil.getCurrentDateTimeStr());
		tAbbAixin.setStatus(0);
		tAbbAixin.setYuliu2(member.getNicename());

		int flag = tAbbAixinMapper.insert(tAbbAixin);
		return flag;
	}

	public Map<String,Object> getQuanminDetail(String axid){
		Map<String,Object> resMap = new HashMap<>();
		TAbbAixin tAbbAixin = tAbbAixinMapper.selectByPrimaryKey(axid);
		resMap.put("data",tAbbAixin);
		resMap.put("success",true);
		resMap.put("msg","获取爱心服务详情成功");
		return resMap;
	}


	public List<TAbbAixin> getMyAixinList(int page,String userid){
		Map<String,Object> paramMap = new HashMap<>();
		paramMap.put("page",page);
		paramMap.put("userid",userid);
		List<TAbbAixin> list = tAbbAixinMapper.getMyAixinList(paramMap);
		return list;
	}


	public Map<String,Object> deleteAixin(String axid){
		Map<String,Object> resMap = new HashMap<>();
		int flag = tAbbAixinMapper.deleteByPrimaryKey(axid);
		if(flag>0){
			resMap.put("msg","删除成功");
		}else{
			resMap.put("msg","删除失败");
		}
		resMap.put("success",true);
		return resMap;
	}
}
